using System.IO;
using CodePlex.TfsLibrary;
using CodePlex.TfsLibrary.Utility;

namespace CodePlex.CodePlexClientLibrary
{
    [Command("applypatch", "Applies a patch to your working directory", MinArgs=1, MaxArgs=1, UsageSummary="<filename> [options]")]
    public class ApplyPatchCommand : AuthenticatedCommand
    {
        readonly IFileSystem fileSystem;

        public ApplyPatchCommand(IFileSystem fileSystem)
        {
            this.fileSystem = fileSystem;
        }

        public override void Execute()
        {
            string filename = Path.GetFullPath(Arguments[0]);

            PatchEngine patchEngine = new PatchEngine(Engine, fileSystem);
            ApplyPatchConsoleView view = new ApplyPatchConsoleView(patchEngine, fileSystem);
            view.Run(Directory.GetCurrentDirectory(), filename);
        }
    }
}